package com.example.system.controller.question;

import com.example.common.core.controller.BaseController;
import com.example.common.core.model.R;
import com.example.common.core.model.TableDataInfo;
import com.example.system.model.question.dto.QuestionAddDTO;
import com.example.system.model.question.dto.QuestionEditDTO;
import com.example.system.model.question.dto.QuestionQueryDTO;
import com.example.system.model.question.vo.QuestionDetailVO;
import com.example.system.service.IQuestionService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 功能描述:
 *
 * @author Lenovo
 * @date 2025/3/22
 */
@RestController
@RequestMapping("/question")
public class QuestionController extends BaseController {

    @Resource
    private IQuestionService questionService;

    @GetMapping("/list")
    public TableDataInfo list(QuestionQueryDTO questionQueryDTO) {
        TableDataInfo tableDataInfo = getTableDataInfo(questionService.list(questionQueryDTO));
        return tableDataInfo;
    }

    @PostMapping("/add")
    public R<Void> add(@RequestBody QuestionAddDTO addDTO) {
        return toResult(questionService.add(addDTO));
    }

    @GetMapping("/detail")
    public R<QuestionDetailVO> detail(Long questionId){
        return R.ok(questionService.detail(questionId));
    }

    @PutMapping("/edit")
    public R<Void> edit(@RequestBody QuestionEditDTO questionEditDTO){
        return toResult(questionService.edit(questionEditDTO));
    }

    @DeleteMapping("/delete")
    public R<Void> delete(Long questionId){
        return toResult(questionService.delete(questionId));
    }
}
